//
// Created by yanhai on 2021/11/4.
//

#include "utility/hash/util_hash_lookup3.h"

#include "packet.h"


Packet *PacketAlloc(unsigned int src_addr, unsigned int dst_addr,
                    unsigned short src_port, unsigned short dst_port,
                    unsigned int time)
{
    auto p = new Packet;
    p->src_addr = src_addr;
    p->dst_addr = dst_addr;
    p->src_port = src_port;
    p->dst_port = dst_port;
    p->time = time;

    unsigned int hash = 0;
    hash = hashlittle_safe(&p->src_addr, sizeof(p->src_addr), hash);
    hash = hashlittle_safe(&p->dst_addr, sizeof(p->dst_addr), hash);
    hash = hashlittle_safe(&p->src_port, sizeof(p->src_port), hash);
    hash = hashlittle_safe(&p->dst_port, sizeof(p->dst_port), hash);

    p->flow_hash = hash;

    return p;
}

void PacketFree(Packet *p)
{
    delete p;
}
